package com.sdp.th.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class Utils {

	/**
	 * 得到错误信息
	 * @param exceptionName
	 * @param exceptionMessage
	 * @param elements
	 * @return
	 */
	public static String stackTraceToString(String exceptionName, String exceptionMessage, StackTraceElement[] elements) {
		StringBuffer strbuff = new StringBuffer();
		for (StackTraceElement stet : elements) {
			strbuff.append(stet + "\n");
		}
		String message = exceptionName + ":" + exceptionMessage + "\n\t" + strbuff.toString();
		return message;
	}
	
	/**
	 * 时间戳转LocalDateTime
	 * @param timestamp
	 * @return
	 */
	public static LocalDateTime timestampToLocalDateTime(long timestamp) {
		return Instant.ofEpochMilli(timestamp)
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
	}
}
